/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.components;

import Model.Cliente;
import Presenter.ClientePresenter;
import Principals.Validadores;
import View.ventas.Frm_RegistrarPedido;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author walter
 */
public class PopUpNuevoCliente extends javax.swing.JDialog{
    private JDesktopPane pnl ;
    private Validadores val = new Validadores() ;
    /**
     * Creates new form Frm_RegistrarCliente
     */
    public PopUpNuevoCliente() {
        initComponents();
        val.desactivarAccionPegar(txtNombres);
        val.desactivarAccionPegar(txtApPaterno);
        val.desactivarAccionPegar(txtApMaterno);
        val.desactivarAccionPegar(txtDocId);
        val.desactivarAccionPegar(txtDireccion);     
        val.desactivarAccionPegar(txtTelefono);
        val.desactivarAccionPegar(txtEmail);        
    }
    
    public PopUpNuevoCliente(JFrame parent) {
        super( parent , true ) ;
        if( parent != null ){
          Dimension parentSize = parent.getSize(); 
          Point p = parent.getLocation(); 
          setLocation(p.x + parentSize.width / 4, p.y + parentSize.height / 4);
        }
        initComponents();
        this.pack();
        this.setVisible(true);    
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
   @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
       pnl = new JDesktopPane() ;
        jToolBar1 = new javax.swing.JToolBar();
        btnToolNuevo = new javax.swing.JButton();
        btnToolModificar = new javax.swing.JButton();
        btnToolGuardar = new javax.swing.JButton();
        btnToolEliminar = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        btnToolLimpiar = new javax.swing.JButton();
        btnToolBuscar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btnToolCancelar = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        pnlRegistrarCliente = new javax.swing.JPanel();
        pnlRegistroCliente = new javax.swing.JPanel();
        lblNombres = new javax.swing.JLabel();
        lblApPaterno = new javax.swing.JLabel();
        lblApMaterno = new javax.swing.JLabel();
        txtNombres = new javax.swing.JTextField();
        txtApPaterno = new javax.swing.JTextField();
        txtApMaterno = new javax.swing.JTextField();
        lblDocId = new javax.swing.JLabel();
        txtDocId = new javax.swing.JTextField();
        pnlUbicacionCliente = new javax.swing.JPanel();
        lblDireccion = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        lblTelefono = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setBorderPainted(false);

        btnToolNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Nuevo.png"))); // NOI18N
        btnToolNuevo.setEnabled(false);
        btnToolNuevo.setFocusable(false);
        btnToolNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolNuevoActionPerformed(evt);
            }
        });
        jToolBar1.add(btnToolNuevo);

        btnToolModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Editar.png"))); // NOI18N
        btnToolModificar.setEnabled(false);
        btnToolModificar.setFocusable(false);
        btnToolModificar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolModificar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolModificarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnToolModificar);

        btnToolGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Guardar.png"))); // NOI18N
        btnToolGuardar.setFocusable(false);
        btnToolGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolGuardarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnToolGuardar);

        btnToolEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Eliminar.png"))); // NOI18N
        btnToolEliminar.setEnabled(false);
        btnToolEliminar.setFocusable(false);
        btnToolEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolEliminarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnToolEliminar);
        jToolBar1.add(jSeparator2);

        btnToolLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Limpiar.png"))); // NOI18N
        btnToolLimpiar.setFocusable(false);
        btnToolLimpiar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolLimpiar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolLimpiarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnToolLimpiar);

        btnToolBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Buscar.png"))); // NOI18N
        btnToolBuscar.setFocusable(false);
        btnToolBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolBuscarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnToolBuscar);
        jToolBar1.add(jSeparator1);

        btnToolCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Cancelar.png"))); // NOI18N
        btnToolCancelar.setFocusable(false);
        btnToolCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolCancelarActionPerformed(evt);
            }
        });
        jToolBar1.add(btnToolCancelar);
        jToolBar1.add(jSeparator3);

        pnlRegistrarCliente.setBorder(javax.swing.BorderFactory.createTitledBorder("Registro"));

        pnlRegistroCliente.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Personales"));

        lblNombres.setText("Nombres*:");
        lblNombres.setToolTipText("");

        lblApPaterno.setText("Apellido Paterno*:");

        lblApMaterno.setText("Apellido Materno*:");

        txtNombres.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombresKeyTyped(evt);
            }
        });

        txtApPaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApPaternoKeyTyped(evt);
            }
        });

        txtApMaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApMaternoKeyTyped(evt);
            }
        });

        lblDocId.setText("Doc. Identidad*:");

        txtDocId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDocIdKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout pnlRegistroClienteLayout = new javax.swing.GroupLayout(pnlRegistroCliente);
        pnlRegistroCliente.setLayout(pnlRegistroClienteLayout);
        pnlRegistroClienteLayout.setHorizontalGroup(
            pnlRegistroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlRegistroClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlRegistroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlRegistroClienteLayout.createSequentialGroup()
                        .addComponent(lblApPaterno)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtApPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlRegistroClienteLayout.createSequentialGroup()
                        .addComponent(lblNombres)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(pnlRegistroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblApMaterno)
                    .addComponent(lblDocId))
                .addGap(18, 18, 18)
                .addGroup(pnlRegistroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtApMaterno, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                    .addComponent(txtDocId))
                .addContainerGap(17, Short.MAX_VALUE))
        );
        pnlRegistroClienteLayout.setVerticalGroup(
            pnlRegistroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlRegistroClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlRegistroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblApMaterno)
                    .addComponent(txtApMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblApPaterno)
                    .addComponent(txtApPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlRegistroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDocId)
                    .addComponent(txtDocId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNombres)
                    .addComponent(txtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlUbicacionCliente.setBorder(javax.swing.BorderFactory.createTitledBorder("Otros Datos"));

        lblDireccion.setText("Dirección*:");

        txtDireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDireccionKeyTyped(evt);
            }
        });

        lblTelefono.setText("Teléfono*:");

        lblEmail.setText("E-mail*:");

        txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyTyped(evt);
            }
        });

        txtEmail.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtEmailKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout pnlUbicacionClienteLayout = new javax.swing.GroupLayout(pnlUbicacionCliente);
        pnlUbicacionCliente.setLayout(pnlUbicacionClienteLayout);
        pnlUbicacionClienteLayout.setHorizontalGroup(
            pnlUbicacionClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlUbicacionClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlUbicacionClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDireccion)
                    .addComponent(lblTelefono)
                    .addComponent(lblEmail))
                .addGap(43, 43, 43)
                .addGroup(pnlUbicacionClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlUbicacionClienteLayout.createSequentialGroup()
                        .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(txtDireccion)
                    .addComponent(txtEmail))
                .addContainerGap())
        );
        pnlUbicacionClienteLayout.setVerticalGroup(
            pnlUbicacionClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlUbicacionClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlUbicacionClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDireccion)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlUbicacionClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTelefono)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlUbicacionClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnlRegistrarClienteLayout = new javax.swing.GroupLayout(pnlRegistrarCliente);
        pnlRegistrarCliente.setLayout(pnlRegistrarClienteLayout);
        pnlRegistrarClienteLayout.setHorizontalGroup(
            pnlRegistrarClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(pnlRegistroCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pnlUbicacionCliente, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pnlRegistrarClienteLayout.setVerticalGroup(
            pnlRegistrarClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlRegistrarClienteLayout.createSequentialGroup()
                .addComponent(pnlRegistroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlUbicacionCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(pnl);
        pnl.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlRegistrarCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlRegistrarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        this.add( pnl ) ;
    }// </editor-fold>                                        
    
    private void btnToolLimpiarActionPerformed(java.awt.event.ActionEvent evt) {                                               
        limpiar() ;
    }                                              

    private void btnToolCancelarActionPerformed(java.awt.event.ActionEvent evt) {                                                
        cerrar() ;
    }                                               

    private void btnToolNuevoActionPerformed(java.awt.event.ActionEvent evt) {                                             
        
    }                                            

    private void btnToolModificarActionPerformed(java.awt.event.ActionEvent evt) {                                                 

    }                                                

    private void btnToolBuscarActionPerformed(java.awt.event.ActionEvent evt) {     
        
    }                                             

    private void btnToolEliminarActionPerformed(java.awt.event.ActionEvent evt) {                                                
        
    }                                               


    private void btnToolGuardarActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try {
            String apPaterno = txtApPaterno.getText();
            String apMaterno = txtApMaterno.getText();
            String nombres = txtNombres.getText();
            String docId = txtDocId.getText();
            String direccion = txtDireccion.getText();
            String telefono = txtTelefono.getText();
            String email = txtEmail.getText();
            String msj_error="";
            boolean error= false;
            
            if (apPaterno.isEmpty() || apMaterno.isEmpty() || nombres.isEmpty() || docId.isEmpty() || direccion.isEmpty() || telefono.isEmpty() || email.isEmpty()) {
                msj_error="Debe ingresar todos los campos obligatorios.";
                error=true;
                //JOptionPane.showMessageDialog(this, "Por favor ingresar todos los campos");
            } //else {
            if (!apPaterno.isEmpty() && apPaterno.length() > 20) {
                if (error) {
                    msj_error = msj_error.concat("\n");
                }
                msj_error = msj_error.concat("El campo Apellido Paterno debe ser máximo de 20 caracteres.");
                error = true;
            }            
            if (!apMaterno.isEmpty() && apMaterno.length() > 20) {
                if (error) {
                    msj_error = msj_error.concat("\n");
                }
                msj_error = msj_error.concat("El campo Apellido Materno debe ser máximo de 20 caracteres.");
                error = true;
            }
            if (!nombres.isEmpty() && nombres.length() > 20) {
                if (error) {
                    msj_error = msj_error.concat("\n");
                }
                msj_error = msj_error.concat("El campo Nombres debe ser máximo de 20 caracteres.");
                error = true;
            }             
                if (!docId.isEmpty()&& docId.length()!=8){
                    if (error) msj_error=msj_error.concat("\n");            
                    msj_error=msj_error.concat("Debe ingresar un Documento de Identidad válido.");
                    error=true;
                }
                
                if (!telefono.isEmpty()&& telefono.length()<7){
                    if (error) msj_error=msj_error.concat("\n");            
                    msj_error=msj_error.concat("Debe ingresar un Teléfono válido.");
                    error=true;                    
                }                
            if (!telefono.isEmpty() && telefono.length() > 10) {
                if (error) {
                    msj_error = msj_error.concat("\n");
                }
                msj_error = msj_error.concat("Debe ingresar un Teléfono válido. (Tamaño máximo 10 dígitos)");
                error = true;
            }            
                if (!email.isEmpty() && !val.validaEmail(email)) {
                    if (error) msj_error=msj_error.concat("\n"); 
                    msj_error=msj_error.concat("Debe ingresar un Email válido.");
                    error=true;
                   if (email.length()>40){
                   if (error) {
                    msj_error = msj_error.concat(" ");
                     }
                   msj_error = msj_error.concat("(Tamaño máximo 40 caracteres)");
                    error = true;
                    }
                } 
                
                if (error){
                    JOptionPane.showMessageDialog(this, msj_error);
                }
                else {
                    int respuesta = JOptionPane.showConfirmDialog(this, "Está seguro de registrar al cliente", "Guardar", JOptionPane.OK_CANCEL_OPTION);
                    switch (respuesta) {
                        case JOptionPane.OK_OPTION:
                            Cliente c=ClientePresenter.existeDocId(docId);
                            if(c!=null)
                            {
                                String msj="El Documento de Identidad ya se encuentra registrado para el cliente:\n";
                                String cli=c.getNombres()+' '+c.getApellidoPaterno()+' '+c.getApellidoMaterno();
                                msj=msj.concat(cli);
                                JOptionPane.showMessageDialog(this, msj);
                                //JOptionPane.showMessageDialog(this, "El Documento de Identidad ya se encuentra registrado para el cliente: ");
                            }
                            else{
                            Cliente cli=ClientePresenter.registrarCliente(apPaterno, apMaterno, nombres, docId, direccion, telefono, email);
                            JOptionPane.showMessageDialog(this, "Se registró al cliente.");
                            regresar(cli);
                            limpiar();
                                
                            }
                            break;
                        case JOptionPane.CANCEL_OPTION:
                            break;
                    }
                    //cambiarVista(new Frm_BuscarCliente());
                }
           // }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "No se pudo realizar la transacción.");
            System.out.println("MENSAJE DE ERROR:" + e);
        }
        
    }                                              

    private void regresar( Cliente cliente ){
        Index p = ( Index )( this.getParent() ) ;
        if( ( p.getContainer().getClass().toString().equals( "class View.ventas.Frm_RegistrarPedido" ) ) ){
            try{
                this.setVisible( false ) ;
                Frm_RegistrarPedido owner = (Frm_RegistrarPedido)p.getContainer() ;
                owner.actualizarDatosCliente( cliente ) ;
            }
            catch (Exception e){
            }
        }
    }                                             

    private void txtApPaternoKeyTyped(java.awt.event.KeyEvent evt) {                                      
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 20, txtApPaterno.getText());
        txtApPaterno.setTransferHandler(null);
    }                                     

    private void txtApMaternoKeyTyped(java.awt.event.KeyEvent evt) {                                      
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 20, txtApMaterno.getText());
        txtApMaterno.setTransferHandler(null);
    }                                     

    private void txtNombresKeyTyped(java.awt.event.KeyEvent evt) {                                    
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 20, txtNombres.getText());
        txtNombres.setTransferHandler(null);
    }                                   

    private void txtDocIdKeyTyped(java.awt.event.KeyEvent evt) {                                  
        val.validaSoloNumeros(evt);
        val.validaMaxSize(evt, 8, txtDocId.getText());
        txtDocId.setTransferHandler(null);
    }                                 

    private void txtDireccionKeyTyped(java.awt.event.KeyEvent evt) {                                      
        val.validaCaracteresDirec(evt);
        val.validaMaxSize(evt, 40, txtDireccion.getText());
        txtDireccion.setTransferHandler(null);
    }                                     

    private void txtTelefonoKeyTyped(java.awt.event.KeyEvent evt) {                                     

        val.validaSoloNumeros(evt);
        val.validaMaxSize(evt, 10, txtTelefono.getText());
        txtTelefono.setTransferHandler(null);

    }                                    

    private void txtEmailKeyTyped(java.awt.event.KeyEvent evt) {                                  

        val.validaCaracteresEmail(evt);
        val.validaMaxSize(evt, 40, txtEmail.getText());
        txtEmail.setTransferHandler(null);
    }
    
    private void limpiar(){
        txtApPaterno.setText( "" ) ;
        txtApMaterno.setText( "" ) ;
        txtNombres.setText( "" ) ;
        txtDocId.setText( "" ) ;
        txtDireccion.setText( "" ) ;
        txtTelefono.setText( "" ) ;
        txtEmail.setText( "" ) ;
    }       
    
    private void cerrar(){
        this.setVisible( false ) ;
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton btnToolBuscar;
    private javax.swing.JButton btnToolCancelar;
    private javax.swing.JButton btnToolEliminar;
    private javax.swing.JButton btnToolGuardar;
    private javax.swing.JButton btnToolLimpiar;
    private javax.swing.JButton btnToolModificar;
    private javax.swing.JButton btnToolNuevo;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lblApMaterno;
    private javax.swing.JLabel lblApPaterno;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblDocId;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblNombres;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JPanel pnlRegistrarCliente;
    private javax.swing.JPanel pnlRegistroCliente;
    private javax.swing.JPanel pnlUbicacionCliente;
    private javax.swing.JTextField txtApMaterno;
    private javax.swing.JTextField txtApPaterno;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtDocId;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtNombres;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration                  
}
